import type { AppRouteRecordRaw, AppRouteModule } from '/@/router/types';

import { PAGE_NOT_FOUND_ROUTE, REDIRECT_ROUTE } from '/@/router/routes/basic';

import { mainOutRoutes } from './mainOut';
import { PageEnum } from '/@/enums/pageEnum';
import { LAYOUT } from '/@/router/constant';
import { t } from '/@/hooks/web/useI18n';

const modules = import.meta.globEager('./modules/**/*.ts');

const routeModuleList: AppRouteModule[] = [];

Object.keys(modules).forEach((key) => {
  const mod = modules[key].default || {};
  const modList = Array.isArray(mod) ? [...mod] : [mod];
  routeModuleList.push(...modList);
});

export const DemoRoute: AppRouteRecordRaw = {
  path: '/demo',
  name: 'Demo',
  component: LAYOUT,
  redirect: '/demo/user',
  meta: {
    icon: 'ion:grid-outline',
    title: '集成测试中',
    ignoreAuth: true,
    orderNo: 20,
  },
  children: [
    {
      path: 'qzj',
      name: 'qzj',
      component: () => import('/@/views/demo/qzj/index.vue'),
      meta: {
        title: '数据维护',
        ignoreAuth: true,
      },
    },
    {
      path: 'user',
      name: 'User',
      component: () => import('/@/views/demo/user/index.vue'),
      meta: {
        title: '用户管理',
        ignoreAuth: true,
      },
    },
    {
      path: 'layout',
      name: 'Layout',
      component: () => import('/@/views/demo/antd/layout.vue'),
      meta: {
        title: 'UI测试-布局',
        ignoreAuth: true,
      },
    },
    {
      path: 'form',
      name: 'Form',
      component: () => import('/@/views/demo/antd/form.vue'),
      meta: {
        title: 'UI测试-表单',
        ignoreAuth: true,
      },
    },
    {
      path: 'CRUD',
      name: 'CRUD',
      component: () => import('/@/views/demo/antd/crud.vue'),
      meta: {
        title: 'UI测试-CRUD',
        ignoreAuth: true,
      },
    },
    //   {
    //     path: 'cesium',
    //     name: 'Cesium',
    //     component: () => import('/@/views/demo/cesium/index.vue'),
    //     meta: {
    //       title: 'cesium',
    //     },
    //   },
  ],
};

export const asyncRoutes = [PAGE_NOT_FOUND_ROUTE, ...routeModuleList];

export const RootRoute: AppRouteRecordRaw = {
  path: '/',
  name: 'Root',
  // redirect: PageEnum.BASE_HOME,
  //测试跳转至单独的首页
  redirect: '/demo',
  meta: {
    title: 'Root',
  },
};

export const LoginRoute: AppRouteRecordRaw = {
  path: '/login',
  name: 'Login',
  component: () => import('/@/views/sys/login/Login.vue'),
  meta: {
    title: t('routes.basic.login'),
  },
};

// Basic routing without permission
export const basicRoutes = [
  LoginRoute,
  RootRoute,
  // DemoRoute,
  ...mainOutRoutes,
  REDIRECT_ROUTE,
  PAGE_NOT_FOUND_ROUTE,
];
